package cn.edu.ctbu.datajpa01.service;

import cn.edu.ctbu.datajpa01.domain.Student;
import cn.edu.ctbu.datajpa01.domain.Teacher;
import cn.edu.ctbu.datajpa01.repository.TeacherRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static org.springframework.data.jpa.domain.AbstractPersistable_.id;

@Service
public class TeacherService {
    @Autowired
    private TeacherRepository teacherRepository;
    //拓展功能函数写在这里
    public List<Teacher> findAll(){
        return teacherRepository.findAll();
    }

    public  Teacher findById(Integer id){return teacherRepository.findById(id).orElse(null);}

    /**
     * 将学生老师添加到表中
     * @param teacher
     */
    public void Insert(Teacher teacher){
        teacherRepository.save(teacher);
    }

    /**
     * 改变表中老师对象的属性
     * @param teacher
     */
    public void upData(Teacher teacher){//对应视频23：50
        teacherRepository.save(teacher);
    }

    /**
     * 删除表中老师对象的属性
     * @param id
     */
    public void delete(Integer id){teacherRepository.deleteById(id);}


}
